﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TomNet.AspNetCore.Mvc;
using TomNet.Caching;

namespace TomNet.Demo.Web.Controllers
{
    public class RedisController : ApiControllerBase
    {
        private static string key = "TomNet";
        private readonly ICache _cache;

        public RedisController(ICache cache)
        {
            _cache = cache;
        }

        [HttpGet]
        public IActionResult Get()
        {
            var result = "";
            if (!_cache.Exists(key))
            {
                _cache.Set(key, "tommyheng");
            }
            result = _cache.Get(key);

            return Ok(result);
        }
    }
}
